#ifndef GLWIDGET_H
#define GLWIDGET_H

#include <QVector>
#include <QtOpenGL/QtOpenGL>
#include <QtOpenGL/QGLWidget>
#include <typeinfo>

#include "Curves/Factories/curvefactory.h"
#include "Curves/Interfaces/icurve.h"
#include "Curves/Objects/bezier.h"
#include "Drawer/curveproperties.h"
#include "Drawer/ogldrawer.h"

typedef ICurve< QPointF > ICurveF;

enum editor_state
{
    Edition,
    Selection
};

enum mouse_state
{
    Zero,
    Moving
};

struct selection
{
    int curve_index;
    int point_index;
};

class GLWidget : public QGLWidget
{
    Q_OBJECT
public:
    explicit GLWidget(QWidget *parent = 0);

    /* Metody. */
    void addCurve( CurveType curveType, int degree );
    void setActiveCurve( int curve ); // Ustawia indeks krzywej, ktora bedziemy edytowac.

protected:
    void initializeGL( );
    void resizeGL( int width, int height );
    void paintGL( );

private:
    CurveFactory< QPointF > factory;
    std::vector< ICurveF* > curves;
    std::vector< CurveProperties > properties;

    enum editor_state editorState;
    enum mouse_state mouseState;

    selection moving_point;
    int active_curve; // Aktywna krzywa.
    OGLDrawer drawer;

    /* Metody. */
    void draw();
    void selection_draw( );
    void mousePressEvent( QMouseEvent* event );
    void mouseMoveEvent( QMouseEvent* event );
    void mouseReleaseEvent( QMouseEvent* event );
    selection curveSelection( int x, int y );

signals:

public slots:
    void reduceDegree( int method, int degree );

};

#endif // GLWIDGET_H
